from typing import Annotated
from fastapi import APIRouter, Depends, HTTPException, Request, Form
from sqlalchemy.orm import Session
from app.common.enums.resp_enum import ErrTypes

from app.utils.resp_util import APIResponse
from app.extensions import dependencies as deps
from app.schemas.common_schema import RequestBody
from app.dependencies.db import get_db

from app.common import exceptions as excs

from app.schemas import merchant as schemas
from app.services import merchant as merc_service

import logging

logger = logging.getLogger(__name__)

router = APIRouter(prefix='/info', tags=['infomation'])
#router = APIRouter(dependencies=[Depends(get_query_token2)],)

@router.get("/merc_info", response_model=schemas.MerchantDetail)
def get_merchant_info(merc_no: str, db: Session = Depends(get_db)):
    logger.info('>> 查询商户信息')
    merc = merc_service.get_merchant_info(db, merc_no=merc_no)
    if merc is None:
        raise excs.GenericException(ErrTypes.db_record_not_found)
        #raise HTTPException(status_code=404, detail="Merchant not found")
    return merc

@router.get("/fee_list", response_model=APIResponse[list[schemas.MerchantFee]])
def get_merchant_fees(merc_no: str, product_code: str=None, db: Session = Depends(get_db)):
    logger.info('>> 查询商户所有费率信息')
    merc_fees = merc_service.get_merchant_fees(db, merc_no=merc_no, product_code=product_code)
    resp = APIResponse()
    resp.data = merc_fees
    return resp

'''
@router.get("/list1", response_model=list[schemas.MerchantDetail])
async def merchant_list(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
    print('>> merchant_list1')
    return merc_service.get_merchants(db)

@router.get("/list", response_model=APIResponse[list[schemas.MerchantDetail]])
async def merchant_list(mercNo, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
    print('>> merchant_list')
    mercs = merc_service.get_merchants(db)
    resp = APIResponse[list[schemas.MerchantDetail]](data=mercs)
    return resp
'''



